package com.zd.springcloud.consumer.service.impl;

import com.zd.springcloud.consumer.mapper.AccountMapper;
import com.zd.springcloud.consumer.service.AccountService;
import com.zd.springcloud.domain.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AccountServiceImpl implements AccountService {

    @Autowired(required = false)
    AccountMapper accountMapper;

    @Override
    public void reduceMoney(double money, long accountId) {
        //判断余额是否从足
        Account account = accountMapper.findAccoutById(accountId);

        if(account.getAccountMoney() < money){
            throw new RuntimeException("您的余额不足" + accountId);
        }

        accountMapper.reduceMoney(money,accountId);

    }
}
